<?php


 class Petitions extends CI_Controller{
	private $offset;
	private $type;
	public function _remap(){
		
		
		$this->get = $this->uri->uri_to_assoc();
		$this->type = $this->uri->segment(2);

		if (isset($this->get['page'])) $this->offset =(int) $this->get['page'];


		if (($this->type !='trending') && ($this->type !='fresh')) $this->type = 'popular';
		if (!isset( $this->offset) && !is_int( $this->offset) ) $this->offset = 0;
		$this->offset = (int) $this->offset;
		$this->main();
	}
	
	public function main(){
		get_instance()->load->model('petitions/Petition');
		$this->load->library('pagination');
		$config['base_url'] = base_url() . get_instance()->config->item('petitions'). '/' . $this->type;
		$config['per_page'] =  10;
		$config['num_links'] = 2 ;
		$config['uri_segment'] = 4; 
		$config['total_rows'] = count(get_instance()->Petition->getSQLresults($this->type));
		$config['prefix'] = '/page/';
		
		
		get_instance()->pagination->initialize($config);
		$data['list'] = get_instance()->Petition->getPetitionsList($this->type, $this->offset, $config['per_page']);			
		
		$content = get_instance()->load->view('content/petition-list-content', $data, TRUE);
		$this->_deployPage($content);

	}
	
	public function _deployPage($content){
		$data['content'] = $content;
		get_instance()->load->view('templates/layout', $data);
	}
	
	
	public function listPetitions(){
		

	}

}